﻿using System;
using System.IO;
using System.Collections.Generic;
using Zove.Runtime.Core;
using Zove.Runtime.Core.Zoom;

namespace Zove.Runtime.Queries {
    public class ZoveQuery {
        public static void Main(string[] args) {
            if (args.Length < 0) {
                Console.WriteLine("Please specify a query file.");
                return;
            }

            ILanguageNature zoomLanguageNature = new ZoomLanguageNature();
            QueryManager qm = new QueryManager(zoomLanguageNature);
            string content = File.ReadAllText(args[0]);
            string[] queries = content.Split(';');
            foreach (string query in queries) {
                if (string.IsNullOrEmpty(query)) {
                    continue;
                }

                Console.WriteLine(query);
                Query q = qm.CreateQuery(query + ";");

                Dictionary<string, QueryResult> results = q.Run();
                foreach (QueryResult result in results.Values) {
                    Console.WriteLine("{0} = {1}", result.Item, result.Value);
                }
            }
        }
    }
}
